package ti.me.longhongbing

import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity
import java.io.File

class HistoryActivity : AppCompatActivity() {

    private val historyFile = "history.txt"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history)

        loadHistory()

        val btnFinish = findViewById<Button>(R.id.btn_finish)
        btnFinish.setOnClickListener {
            finish()
        }
    }

    private fun loadHistory() {
        val file = File(filesDir, historyFile)
        if (file.exists()) {
            val history = file.readLines()
            val history_list = findViewById<ListView>(R.id.history_list)
            history_list.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, history)
        }
    }
}